package com.technology.education.ui.common.manage_account

import androidx.lifecycle.MutableLiveData
import com.technology.education.data.SpKeys
import com.technology.education.ext.postEventBus
import com.technology.education.ext.toast
import com.technology.education.network.apiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

class ManageAccountViewModel : BaseViewModel() {
    val result = MutableLiveData<String>()
    val bindResult = MutableLiveData<Boolean>()
    fun updateHeader(avatar: String) {
        request({ apiService.updateInfo(hashMapOf("avatar" to avatar)) }, success = {
            postEventBus(SpKeys.UPDATE_USER_AVATAR, avatar)
        }, error = { toast(it.errorMsg) }, isShowDialog = true)
    }

    fun bindWx(hashMap: HashMap<String, Any?>) {
        request({ apiService.bindWechat(hashMap) }, success = {
            bindResult.postValue(true)
        }, error = {
            toast(it.errorMsg)
        })
    }
}